namespace CSharpPro._1009;

public class Demo
{
    public void TestPrint()
    {
        Console.WriteLine("=== 1000以内的水仙花数 ===");
        
        int count = 0;
        for (int num = 100; num < 1000; num++)  
        {
            int hundreds = num / 100;        
            int tens = (num % 100) / 10;      
            int units = num % 10;             
            
            int sum = hundreds * hundreds * hundreds 
                      + tens * tens * tens 
                      + units * units * units;
            
           
            if (sum == num)
            {
                count ++;
                Console.WriteLine($"{num} = {hundreds}³ + {tens}³ + {units}³");
            }
        }
        
        Console.WriteLine($"\n1000以内共有 {count} 个水仙花数");
    }

    //输出100以内所有的质数
    public void TestPrint2()
    {
        Console.WriteLine("=== 100以内的所有质数 ===");
        int count = 0;
        
        for (int num = 2; num <= 100; num++)
        {
            bool isPrime = true;
            
            // 判断num是否为质数
            for (int i = 2; i <= Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    isPrime = false;
                    break;
                }
            }
            
            if (isPrime)
            {
                Console.Write($"{num,3} ");
                count++;
                
                // 每10个质数换一行
                if (count % 10 == 0)
                {
                    Console.WriteLine();
                }
            }
        }
        
        Console.WriteLine($"\n\n100以内共有 {count} 个质数"); 
    }
    
}